home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / ideas / draw_logo_shadow.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  14KB  |  489 lines

  1. /*
  2.  * (c) Copyright 1993, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED 
  4.  * Permission to use, copy, modify, and distribute this software for 
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that 
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission. 
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  * 
  25.  * US Government Users Restricted Rights 
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37. #include <GL/gl.h>
  38.  
  39. #include "objects.h"
  40.  
  41. static float scp[18][3] = {
  42.   {1.000000, 0.000000, 0.000000},    {1.000000, 0.000000, 5.000000},
  43.   {0.707107, 0.707107, 0.000000},    {0.707107, 0.707107, 5.000000},
  44.   {0.000000, 1.000000, 0.000000},    {0.000000, 1.000000, 5.000000},
  45.   {-0.707107, 0.707107, 0.000000},    {-0.707107, 0.707107, 5.000000},
  46.   {-1.000000, 0.000000, 0.000000},    {-1.000000, 0.000000, 5.000000},
  47.   {-0.707107, -0.707107, 0.000000},    {-0.707107, -0.707107, 5.000000},
  48.   {0.000000, -1.000000, 0.000000},    {0.000000, -1.000000, 5.000000},
  49.   {0.707107, -0.707107, 0.000000},    {0.707107, -0.707107, 5.000000},
  50.   {1.000000, 0.000000, 0.000000},    {1.000000, 0.000000, 5.000000},
  51. };
  52.  
  53. static float dcp[18][3] = {
  54.   {1.000000, 0.000000, 0.000000},    {1.000000, 0.000000, 7.000000},
  55.   {0.707107, 0.707107, 0.000000},    {0.707107, 0.707107, 7.000000},
  56.   {0.000000, 1.000000, 0.000000},    {0.000000, 1.000000, 7.000000},
  57.   {-0.707107, 0.707107, 0.000000},    {-0.707107, 0.707107, 7.000000},
  58.   {-1.000000, 0.000000, 0.000000},    {-1.000000, 0.000000, 7.000000},
  59.   {-0.707107, -0.707107, 0.000000},    {-0.707107, -0.707107, 7.000000},
  60.   {0.000000, -1.000000, 0.000000},    {0.000000, -1.000000, 7.000000},
  61.   {0.707107, -0.707107, 0.000000},    {0.707107, -0.707107, 7.000000},
  62.   {1.000000, 0.000000, 0.000000},    {1.000000, 0.000000, 7.000000},
  63. };
  64.  
  65. static float ep[9][9][3] = {
  66.   {
  67.     {1.000000, 0.000000, 0.000000},
  68.     {0.707107, 0.707107, 0.000000},
  69.     {0.000000, 1.000000, 0.000000},
  70.     {-0.707107, 0.707107, 0.000000},
  71.     {-1.000000, 0.000000, 0.000000},
  72.     {-0.707107, -0.707107, 0.000000},
  73.     {0.000000, -1.000000, 0.000000},
  74.     {0.707107, -0.707107, 0.000000},
  75.     {1.000000, 0.000000, 0.000000},
  76.   },
  77.   
  78.   {
  79.     {1.000000, 0.019215, 0.195090},
  80.     {0.707107, 0.712735, 0.057141},
  81.     {0.000000, 1.000000, 0.000000},
  82.     {-0.707107, 0.712735, 0.057141},
  83.     {-1.000000, 0.019215, 0.195090},
  84.     {-0.707107, -0.674305, 0.333040},
  85.     {0.000000, -0.961571, 0.390181},
  86.     {0.707107, -0.674305, 0.333040},
  87.     {1.000000, 0.019215, 0.195090},
  88.   },
  89.   
  90.   {
  91.     {1.000000, 0.076120, 0.382683},
  92.     {0.707107, 0.729402, 0.112085},
  93.     {0.000000, 1.000000, 0.000000},
  94.     {-0.707107, 0.729402, 0.112085},
  95.     {-1.000000, 0.076120, 0.382683},
  96.     {-0.707107, -0.577161, 0.653282},
  97.     {0.000000, -0.847759, 0.765367},
  98.     {0.707107, -0.577161, 0.653282},
  99.     {1.000000, 0.076120, 0.382683},
  100.   },
  101.   
  102.   {
  103.     {1.000000, 0.168530, 0.555570},
  104.     {0.707107, 0.756468, 0.162723},
  105.     {0.000000, 1.000000, 0.000000},
  106.     {-0.707107, 0.756468, 0.162723},
  107.     {-1.000000, 0.168530, 0.555570},
  108.     {-0.707107, -0.419407, 0.948418},
  109.     {0.000000, -0.662939, 1.111140},
  110.     {0.707107, -0.419407, 0.948418},
  111.     {1.000000, 0.168530, 0.555570},
  112.   },
  113.   
  114.   {
  115.     {1.000000, 0.292893, 0.707107},
  116.     {0.707107, 0.792893, 0.207107},
  117.     {0.000000, 1.000000, 0.000000},
  118.     {-0.707107, 0.792893, 0.207107},
  119.     {-1.000000, 0.292893, 0.707107},
  120.     {-0.707107, -0.207107, 1.207107},
  121.     {0.000000, -0.414214, 1.414214},
  122.     {0.707107, -0.207107, 1.207107},
  123.     {1.000000, 0.292893, 0.707107},
  124.   },
  125.   
  126.   {
  127.     {1.000000, 0.444430, 0.831470},
  128.     {0.707107, 0.837277, 0.243532},
  129.     {0.000000, 1.000000, 0.000000},
  130.     {-0.707107, 0.837277, 0.243532},
  131.     {-1.000000, 0.444430, 0.831470},
  132.     {-0.707107, 0.051582, 1.419407},
  133.     {0.000000, -0.111140, 1.662939},
  134.     {0.707107, 0.051582, 1.419407},
  135.     {1.000000, 0.444430, 0.831470},
  136.   },
  137.   
  138.   {
  139.     {1.000000, 0.617317, 0.923880},
  140.     {0.707107, 0.887915, 0.270598},
  141.     {0.000000, 1.000000, 0.000000},
  142.     {-0.707107, 0.887915, 0.270598},
  143.     {-1.000000, 0.617317, 0.923880},
  144.     {-0.707107, 0.346719, 1.577161},
  145.     {0.000000, 0.234633, 1.847759},
  146.     {0.707107, 0.346719, 1.577161},
  147.     {1.000000, 0.617317, 0.923880},
  148.   },
  149.   
  150.   {
  151.     {1.000000, 0.804910, 0.980785},
  152.     {0.707107, 0.942859, 0.287265},
  153.     {0.000000, 1.000000, 0.000000},
  154.     {-0.707107, 0.942859, 0.287265},
  155.     {-1.000000, 0.804910, 0.980785},
  156.     {-0.707107, 0.666960, 1.674305},
  157.     {0.000000, 0.609819, 1.961571},
  158.     {0.707107, 0.666960, 1.674305},
  159.     {1.000000, 0.804910, 0.980785},
  160.   },
  161.   
  162.   {
  163.     {1.000000, 1.000000, 1.000000},
  164.     {0.707107, 1.000000, 0.292893},
  165.     {0.000000, 1.000000, 0.000000},
  166.     {-0.707107, 1.000000, 0.292893},
  167.     {-1.000000, 1.000000, 1.000000},
  168.     {-0.707107, 1.000000, 1.707107},
  169.     {0.000000, 1.000000, 2.000000},
  170.     {0.707107, 1.000000, 1.707107},
  171.     {1.000000, 1.000000, 1.000000},
  172.   },
  173.   
  174. };
  175.  
  176. static void draw_single_cylinder(void) {
  177.   
  178.   glBegin(GL_TRIANGLE_STRIP);
  179.   glVertex3fv(scp[0]);
  180.   glVertex3fv(scp[1]);
  181.   glVertex3fv(scp[2]);
  182.   glVertex3fv(scp[3]);
  183.   glVertex3fv(scp[4]);
  184.   glVertex3fv(scp[5]);
  185.   glVertex3fv(scp[6]);
  186.   glVertex3fv(scp[7]);
  187.   glVertex3fv(scp[8]);
  188.   glVertex3fv(scp[9]);
  189.   glVertex3fv(scp[10]);
  190.   glVertex3fv(scp[11]);
  191.   glVertex3fv(scp[12]);
  192.   glVertex3fv(scp[13]);
  193.   glVertex3fv(scp[14]);
  194.   glVertex3fv(scp[15]);
  195.   glVertex3fv(scp[16]);
  196.   glVertex3fv(scp[17]);
  197.   glEnd();
  198. }
  199.  
  200. static void draw_double_cylinder(void) {
  201.   
  202.   glBegin(GL_TRIANGLE_STRIP);
  203.   glVertex3fv(dcp[0]);
  204.   glVertex3fv(dcp[1]);
  205.   glVertex3fv(dcp[2]);
  206.   glVertex3fv(dcp[3]);
  207.   glVertex3fv(dcp[4]);
  208.   glVertex3fv(dcp[5]);
  209.   glVertex3fv(dcp[6]);
  210.   glVertex3fv(dcp[7]);
  211.   glVertex3fv(dcp[8]);
  212.   glVertex3fv(dcp[9]);
  213.   glVertex3fv(dcp[10]);
  214.   glVertex3fv(dcp[11]);
  215.   glVertex3fv(dcp[12]);
  216.   glVertex3fv(dcp[13]);
  217.   glVertex3fv(dcp[14]);
  218.   glVertex3fv(dcp[15]);
  219.   glVertex3fv(dcp[16]);
  220.   glVertex3fv(dcp[17]);
  221.   glEnd();
  222. }
  223.  
  224. static void  draw_elbow(void) {
  225.   
  226.   glBegin(GL_TRIANGLE_STRIP);
  227.   glVertex3fv(ep[0][0]);
  228.   glVertex3fv(ep[1][0]);
  229.   glVertex3fv(ep[0][1]);
  230.   glVertex3fv(ep[1][1]);
  231.   glVertex3fv(ep[0][2]);
  232.   glVertex3fv(ep[1][2]);
  233.   glVertex3fv(ep[0][3]);
  234.   glVertex3fv(ep[1][3]);
  235.   glVertex3fv(ep[0][4]);
  236.   glVertex3fv(ep[1][4]);
  237.   glVertex3fv(ep[0][5]);
  238.   glVertex3fv(ep[1][5]);
  239.   glVertex3fv(ep[0][6]);
  240.   glVertex3fv(ep[1][6]);
  241.   glVertex3fv(ep[0][7]);
  242.   glVertex3fv(ep[1][7]);
  243.   glVertex3fv(ep[0][8]);
  244.   glVertex3fv(ep[1][8]);
  245.   glEnd();
  246.   glBegin(GL_TRIANGLE_STRIP);
  247.   glVertex3fv(ep[1][0]);
  248.   glVertex3fv(ep[2][0]);
  249.   glVertex3fv(ep[1][1]);
  250.   glVertex3fv(ep[2][1]);
  251.   glVertex3fv(ep[1][2]);
  252.   glVertex3fv(ep[2][2]);
  253.   glVertex3fv(ep[1][3]);
  254.   glVertex3fv(ep[2][3]);
  255.   glVertex3fv(ep[1][4]);
  256.   glVertex3fv(ep[2][4]);
  257.   glVertex3fv(ep[1][5]);
  258.   glVertex3fv(ep[2][5]);
  259.   glVertex3fv(ep[1][6]);
  260.   glVertex3fv(ep[2][6]);
  261.   glVertex3fv(ep[1][7]);
  262.   glVertex3fv(ep[2][7]);
  263.   glVertex3fv(ep[1][8]);
  264.   glVertex3fv(ep[2][8]);
  265.   glEnd();
  266.   glBegin(GL_TRIANGLE_STRIP);
  267.   glVertex3fv(ep[2][0]);
  268.   glVertex3fv(ep[3][0]);
  269.   glVertex3fv(ep[2][1]);
  270.   glVertex3fv(ep[3][1]);
  271.   glVertex3fv(ep[2][2]);
  272.   glVertex3fv(ep[3][2]);
  273.   glVertex3fv(ep[2][3]);
  274.   glVertex3fv(ep[3][3]);
  275.   glVertex3fv(ep[2][4]);
  276.   glVertex3fv(ep[3][4]);
  277.   glVertex3fv(ep[2][5]);
  278.   glVertex3fv(ep[3][5]);
  279.   glVertex3fv(ep[2][6]);
  280.   glVertex3fv(ep[3][6]);
  281.   glVertex3fv(ep[2][7]);
  282.   glVertex3fv(ep[3][7]);
  283.   glVertex3fv(ep[2][8]);
  284.   glVertex3fv(ep[3][8]);
  285.   glEnd();
  286.   glBegin(GL_TRIANGLE_STRIP);
  287.   glVertex3fv(ep[3][0]);
  288.   glVertex3fv(ep[4][0]);
  289.   glVertex3fv(ep[3][1]);
  290.   glVertex3fv(ep[4][1]);
  291.   glVertex3fv(ep[3][2]);
  292.   glVertex3fv(ep[4][2]);
  293.   glVertex3fv(ep[3][3]);
  294.   glVertex3fv(ep[4][3]);
  295.   glVertex3fv(ep[3][4]);
  296.   glVertex3fv(ep[4][4]);
  297.   glVertex3fv(ep[3][5]);
  298.   glVertex3fv(ep[4][5]);
  299.   glVertex3fv(ep[3][6]);
  300.   glVertex3fv(ep[4][6]);
  301.   glVertex3fv(ep[3][7]);
  302.   glVertex3fv(ep[4][7]);
  303.   glVertex3fv(ep[3][8]);
  304.   glVertex3fv(ep[4][8]);
  305.   glEnd();
  306.   glBegin(GL_TRIANGLE_STRIP);
  307.   glVertex3fv(ep[4][0]);
  308.   glVertex3fv(ep[5][0]);
  309.   glVertex3fv(ep[4][1]);
  310.   glVertex3fv(ep[5][1]);
  311.   glVertex3fv(ep[4][2]);
  312.   glVertex3fv(ep[5][2]);
  313.   glVertex3fv(ep[4][3]);
  314.   glVertex3fv(ep[5][3]);
  315.   glVertex3fv(ep[4][4]);
  316.   glVertex3fv(ep[5][4]);
  317.   glVertex3fv(ep[4][5]);
  318.   glVertex3fv(ep[5][5]);
  319.   glVertex3fv(ep[4][6]);
  320.   glVertex3fv(ep[5][6]);
  321.   glVertex3fv(ep[4][7]);
  322.   glVertex3fv(ep[5][7]);
  323.   glVertex3fv(ep[4][8]);
  324.   glVertex3fv(ep[5][8]);
  325.   glEnd();
  326.   glBegin(GL_TRIANGLE_STRIP);
  327.   glVertex3fv(ep[5][0]);
  328.   glVertex3fv(ep[6][0]);
  329.   glVertex3fv(ep[5][1]);
  330.   glVertex3fv(ep[6][1]);
  331.   glVertex3fv(ep[5][2]);
  332.   glVertex3fv(ep[6][2]);
  333.   glVertex3fv(ep[5][3]);
  334.   glVertex3fv(ep[6][3]);
  335.   glVertex3fv(ep[5][4]);
  336.   glVertex3fv(ep[6][4]);
  337.   glVertex3fv(ep[5][5]);
  338.   glVertex3fv(ep[6][5]);
  339.   glVertex3fv(ep[5][6]);
  340.   glVertex3fv(ep[6][6]);
  341.   glVertex3fv(ep[5][7]);
  342.   glVertex3fv(ep[6][7]);
  343.   glVertex3fv(ep[5][8]);
  344.   glVertex3fv(ep[6][8]);
  345.   glEnd();
  346.   glBegin(GL_TRIANGLE_STRIP);
  347.   glVertex3fv(ep[6][0]);
  348.   glVertex3fv(ep[7][0]);
  349.   glVertex3fv(ep[6][1]);
  350.   glVertex3fv(ep[7][1]);
  351.   glVertex3fv(ep[6][2]);
  352.   glVertex3fv(ep[7][2]);
  353.   glVertex3fv(ep[6][3]);
  354.   glVertex3fv(ep[7][3]);
  355.   glVertex3fv(ep[6][4]);
  356.   glVertex3fv(ep[7][4]);
  357.   glVertex3fv(ep[6][5]);
  358.   glVertex3fv(ep[7][5]);
  359.   glVertex3fv(ep[6][6]);
  360.   glVertex3fv(ep[7][6]);
  361.   glVertex3fv(ep[6][7]);
  362.   glVertex3fv(ep[7][7]);
  363.   glVertex3fv(ep[6][8]);
  364.   glVertex3fv(ep[7][8]);
  365.   glEnd();
  366.   glBegin(GL_TRIANGLE_STRIP);
  367.   glVertex3fv(ep[7][0]);
  368.   glVertex3fv(ep[8][0]);
  369.   glVertex3fv(ep[7][1]);
  370.   glVertex3fv(ep[8][1]);
  371.   glVertex3fv(ep[7][2]);
  372.   glVertex3fv(ep[8][2]);
  373.   glVertex3fv(ep[7][3]);
  374.   glVertex3fv(ep[8][3]);
  375.   glVertex3fv(ep[7][4]);
  376.   glVertex3fv(ep[8][4]);
  377.   glVertex3fv(ep[7][5]);
  378.   glVertex3fv(ep[8][5]);
  379.   glVertex3fv(ep[7][6]);
  380.   glVertex3fv(ep[8][6]);
  381.   glVertex3fv(ep[7][7]);
  382.   glVertex3fv(ep[8][7]);
  383.   glVertex3fv(ep[7][8]);
  384.   glVertex3fv(ep[8][8]);
  385.   glEnd();
  386. }
  387.  
  388. static void bend_forward(void) {
  389.   
  390.   glTranslatef(0.0, 1.000000, 0.0);
  391.   glRotatef (0.1 * (900), 1.0, 0.0, 0.0);
  392.   glTranslatef(0.0, -1.000000, 0.0);
  393. }
  394.  
  395. static void bend_left(void) {
  396.   
  397.   glRotatef (0.1 * (-900), 0.0, 0.0, 1.0);
  398.   glTranslatef(0.0, 1.000000, 0.0);
  399.   glRotatef (0.1 * (900), 1.0, 0.0, 0.0);
  400.   glTranslatef(0.0, -1.000000, 0.0);
  401. }
  402.  
  403. static void bend_right(void) {
  404.  
  405.   glRotatef (0.1 * (900), 0.0, 0.0, 1.0);
  406.   glTranslatef(0.0, 1.000000, 0.0);
  407.   glRotatef (0.1 * (900), 1.0, 0.0, 0.0);
  408.   glTranslatef(0.0, -1.000000, 0.0);
  409. }
  410.  
  411. void draw_logo_shadow(void) {
  412.   
  413.   glTranslatef(5.500000,  -3.500000,  4.500000);
  414.   
  415.   glTranslatef(0.0,  0.0,  -7.000000);
  416.   draw_double_cylinder();
  417.   bend_forward();
  418.   draw_elbow();
  419.   glTranslatef(0.0,  0.0,  -7.000000);
  420.   draw_double_cylinder();
  421.   bend_forward();
  422.   draw_elbow();
  423.   glTranslatef(0.0,  0.0,  -5.000000);
  424.   draw_single_cylinder();
  425.   bend_right();
  426.   draw_elbow();
  427.   glTranslatef(0.0,  0.0,  -7.000000);
  428.   draw_double_cylinder();
  429.   bend_forward();
  430.   draw_elbow();
  431.   glTranslatef(0.0,  0.0,  -7.000000);
  432.   draw_double_cylinder();
  433.   bend_forward();
  434.   draw_elbow();
  435.   glTranslatef(0.0,  0.0,  -5.000000);
  436.   draw_single_cylinder();
  437.   bend_left();
  438.   draw_elbow();
  439.   glTranslatef(0.0,  0.0,  -7.000000);
  440.   draw_double_cylinder();
  441.   bend_forward();
  442.   draw_elbow();
  443.   glTranslatef(0.0,  0.0,  -7.000000);
  444.   draw_double_cylinder();
  445.   bend_forward();
  446.   draw_elbow();
  447.   glTranslatef(0.0,  0.0,  -5.000000);
  448.   draw_single_cylinder();
  449.   bend_right();
  450.   draw_elbow();
  451.   glTranslatef(0.0,  0.0,  -7.000000);
  452.   draw_double_cylinder();
  453.   bend_forward();
  454.   draw_elbow();
  455.   glTranslatef(0.0,  0.0,  -7.000000);
  456.   draw_double_cylinder();
  457.   bend_forward();
  458.   draw_elbow();
  459.   glTranslatef(0.0,  0.0,  -5.000000);
  460.   draw_single_cylinder();
  461.   bend_left();
  462.   draw_elbow();
  463.   glTranslatef(0.0,  0.0,  -7.000000);
  464.   draw_double_cylinder();
  465.   bend_forward();
  466.   draw_elbow();
  467.   glTranslatef(0.0,  0.0,  -7.000000);
  468.   draw_double_cylinder();
  469.   bend_forward();
  470.   draw_elbow();
  471.   glTranslatef(0.0,  0.0,  -5.000000);
  472.   draw_single_cylinder();
  473.   bend_right();
  474.   draw_elbow();
  475.   glTranslatef(0.0,  0.0,  -7.000000);
  476.   draw_double_cylinder();
  477.   bend_forward();
  478.   draw_elbow();
  479.   glTranslatef(0.0,  0.0,  -7.000000);
  480.   draw_double_cylinder();
  481.   bend_forward();
  482.   draw_elbow();
  483.   glTranslatef(0.0,  0.0,  -5.000000);
  484.   draw_single_cylinder();
  485.   bend_left();
  486.   draw_elbow();
  487. }
  488.  
  489.